import React, { Component } from "react";
import Co from "../co/co";
import Co1 from "../co1/co1";

import Middle from '../middle/middle'
export const {Provider, Consumer} = React.createContext('div') // 创建一个context对象。组件会向组件所处的树中距离最近的那个Provider进行匹配context。当组件所处的树没有匹配到Provider (不使用Provider组件) 时，defaultValue参数才会生效。



class com extends Component {
  constructor (props){
    super(props)
    this.state={
        money:25
    }
}
  handleClick(){
    // console.log('111111')
    
    this.refs.children.childrenMethod();
  }
  callback2(a,b,c){ 
   console.log(a,b,c,'=============')
  }
  render() {
    let data = 123;
    return (
      <div>
        <span onClick={this.handleClick.bind(this)}>我是父组件</span> 
        <Co ref="children" callback={this.callback2.bind(this)}  name={data} />
        <Co1>
          <span>hello</span>
          <span>world</span>
        </Co1>
         
         {/* 多个组件传值 */}
        <Provider value={this.state.money}>
                <Middle></Middle>      
            </Provider> 
      </div>
    );
  }
}

export default com;
